package ms.spm.implement;

import java.lang.reflect.Method;

import ms.spm.IAppContext;
import ms.spm.services.MethodProvider;
import ms.utils.ExceptionUtil;

public class SimpleMethodProvider implements MethodProvider {

	Object target;
	IAppContext context;
	
	public SimpleMethodProvider(Object target, IAppContext context) {
		this.target = target;
		this.context = context;
	}
	
	@Override
	public Object getMethodTarget(String name) {
		return target;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Method resolveMethod(String name, Class... parameter) {
		try {
			Method result = target.getClass().getDeclaredMethod(name, parameter);
			result.setAccessible(true);
			return result;
		} catch (Exception e) {
			ExceptionUtil.handle(e, context);
			return null;
		}
	}

}
